package com.gensdai.leliang.adapter;

import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.gensdai.leliang.R;
import com.gensdai.leliang.entity.parseBean.BaseParse;
import com.gensdai.leliang.remoteInterface.URLConfig;
import com.gensdai.leliang.utils.ViewHolder;

/**
 * 订单详情里面产品的列表 适配器
 * Created by Administrator on 2017/6/9.
 */

public class OrderInfoProductListAdapter extends KimiraAdapter<BaseParse.OrderAttributeMapBean> {

    LayoutInflater inflater;
    Context context;
    boolean showstock = true;

    public OrderInfoProductListAdapter(Context context) {
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
    }
    public OrderInfoProductListAdapter(Context context,boolean isshowstock) {
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
        this.showstock = isshowstock;
    }

    @Override
    public View extralView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_order_info_product_list,
                    null);
        }

        SimpleDraweeView icon = ViewHolder.GetChars(convertView, R.id.productIcon);
        TextView productName = ViewHolder.GetChars(convertView, R.id.title);
        TextView productAttr = ViewHolder.GetChars(convertView, R.id.info);
        TextView stocknum = ViewHolder.GetChars(convertView, R.id.stocknum);
        TextView price = ViewHolder.GetChars(convertView, R.id.money);
        TextView oldprice = ViewHolder.GetChars(convertView, R.id.oldmoney);
        TextView oldPrice = ViewHolder.GetChars(convertView, R.id.oldmoney);
        TextView count = ViewHolder.GetChars(convertView, R.id.count);

        BaseParse.OrderAttributeMapBean bean = (BaseParse.OrderAttributeMapBean) getItem(position);

        String imguri = "";
        if(!TextUtils.isEmpty(bean.logo)){
            imguri = URLConfig.BASEDOMAIN + bean.logo;
        }
        icon.setImageURI(Uri.parse(imguri));
        productName.setText(bean.productName);
        productAttr.setText(bean.attributeName);


        if(showstock){
            if(bean.stockNum <= 10){
                stocknum.setVisibility(View.VISIBLE);
                stocknum.setText(String.format(context.getText(R.string.order_stock_num).toString(), bean.stockNum));
            }else{
                stocknum.setVisibility(View.GONE);
            }
        }else{
            stocknum.setVisibility(View.GONE);
        }
        //单价
        price.setText(String.format(context.getText(R.string.product_price).toString(), bean.buyPrice + ""));
//        oldPrice.setText("￥1");
        // 设置中划线并加清晰
//        oldprice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        //数量
        count.setText("x " + bean.buyNum + "");

        return convertView;
    }
}
